#ifndef AUTOORDERBASE_H
#define AUTOORDERBASE_H

#include <assert.h>
#include "core/order/ordermanager.h"
#include "core/bar/bars.h"

class AutoOrderConfirm
{
public:
    virtual bool getConfirm(OrderBase *order) = 0;
};

class AutoOrderBase
{
public:
    AutoOrderBase();
    int setIndex(int index);
    Bars* setBars(Bars *bars);
    bool OnNewTick(double price, time_t time);
    NormalOrder* createBuyOrder(int time, const char *symbol, double price, double lots, double stoploss, double takeprofit, int magic);
    NormalOrder* createSellOrder(int time, const char *symbol, double price, double lots, double stoploss, double takeprofit, int magic);
    virtual void newTick(double price, time_t time) = 0;
    inline bool getEnabled() const { return m_enabled; }
    inline void setEnabled(bool enable) { m_enabled = enable; }
    inline bool getNeedConfirm() const { return m_needConfirm && m_enabled && m_autoOrderConfirm; }
    inline void setNeedConfirm(bool needConfirm) { m_needConfirm = needConfirm; }
    bool getUserConfirm(OrderBase *order);
    void setAutoOrderConfirm(AutoOrderConfirm *autoOrderConfirm) { m_autoOrderConfirm = autoOrderConfirm; }

protected:
    inline double open(int index) { assert (index >= 0); return (*m_bars)[index + m_index].getOpenValue(); }
    inline double close(int index) { assert (index >= 0); return (*m_bars)[index + m_index].getCloseValue(); }
    inline double high(int index) { assert (index >= 0); return (*m_bars)[index + m_index].getHighValue(); }
    inline double low(int index) { assert (index >= 0); return (*m_bars)[index + m_index].getLowValue(); }
    OrderManager *m_orderManager;
    bool m_enabled;
    bool m_needConfirm;
    bool m_returnContinue;
    Bars *m_bars;
    int m_index;
    double m_price;
    double m_time;

    AutoOrderConfirm *m_autoOrderConfirm;
};

#endif